package com.bs.manager05.utils;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 小姚
 * @pakeageName:com.bs.product03.utils
 * @ClassName:MetaObjectConfig
 * @Descirption:
 * @data 2022/11/7 19:31
 */
@Slf4j
@Component
public class DateTimeConfig implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String format1 = df.format(new Date());
        this.strictInsertFill(metaObject,"createTime",String.class,format1);
        this.strictUpdateFill(metaObject,"updateTime",String.class,format1);
    }



    @Override
    public void updateFill(MetaObject metaObject) {
        SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String format1 = df.format(new Date());
        this.strictUpdateFill(metaObject,"updateTime",String.class,format1);
    }
}
